package com.yixing.tech.system.dao;

import com.yixing.tech.system.po.Button;
import com.yixing.tech.system.po.WebPage;
import com.yixing.tech.common.utils.DataUtil;
import com.yixing.tech.common.vo.s3.ButtonVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

/**
 * @author yixing tech
 * * @date 2022/1/5
 */
@Repository
public class WebPageDao {

    @Autowired
    private MongoTemplate mongoTemplate;

    public void addButton(ButtonVO vo) {
        Query query = new Query(Criteria.where("id").is(vo.getWebPageId()));
        //文档内嵌
        Update update = new Update();
        Button button = DataUtil.o2o(vo, Button.class);
        update.addToSet("buttons", button);
        mongoTemplate.upsert(query, update, WebPage.class);
    }
}
